Component({
  /**
   * 组件的属性列表
   */
  properties: {
    tempath:{
      type:Array,
      value:[]
    },
    number:{
      type:Number,
      value:0
    },
    is_discuss:{
      type:Number,
      value:0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    tempath:[],
    number:0
  },

  /**
   * 组件的方法列表
   */
  methods: {

    uploadDetailImage: function (e) { //这里是选取图片的方法
      var that = this;
      var tempath = [];
      wx.setStorageSync('tempath', tempath);
      var pics = [];
      console.log(that.properties.is_discuss);
      if(that.properties.is_discuss == 0 && that.properties.number == 1){
        wx.showToast({
          title: '最多选择' + 1 + '张！',
          icon: 'none'
        })
        return;
      }
      pics = that.data.tempath;
      if (pics.length >= 4) {
        wx.showToast({
          title: '最多选择' + pics.length + '张！',
          icon: 'none'
        })
        return;
      }
      wx.chooseImage({
        count:4,
        sizeType: ['compressed'],
        success: function(res) {
          var imgs = res.tempFilePaths;
          for (var i = 0; i < imgs.length; i++) {
            pics.push(imgs[i])
          }
          that.setData({
            tempath:pics
          })
          console.log(that.data.tempath);
        },
        complete:res =>{
          wx.setStorageSync('tempath', that.data.tempath);
          var number = pics.length;
          that.setData({
            number:number
          })
        }
      })
    },
    deleteImg:function(e){
      var that = this;
      var images = that.data.tempath;
      var index = e.currentTarget.dataset.id;
      wx.showModal({
        title: '提示',
        content: '确定要删除此图片吗？',
        success: function (res) {
          if (res.confirm) {
            images.splice(index, 1);
            console.log(images)
          } else if (res.cancel) {
            return false;
          }
          that.setData({
            tempath:images
          });
        },
        complete:res => {
          wx.setStorageSync('tempath', that.data.tempath);
          var number = images.length;
          that.setData({
            number:number
          })
        }
      })
    }
  }
})
